#include "Utils.h"
#include "ListNode.h"
#include "TreeNode.h"
#include <iostream>
#include <vector>
#include <string>
#include <unordered_set>

using namespace std;

class Issue202 {
public:
	bool isHappy(int n) {
		if (n < 1)
			return false;
		if (n == 1)
			return true;
		unordered_set<int> showedNums;
		showedNums.insert(n);

		while(true)
		{
			int s = 0;
			while(n)
			{
				s += (n % 10) * (n % 10);
				n = n / 10;
			}

			if (s == 1)
				return true;
			else if (showedNums.find(s) != showedNums.end())
				return false;
			n = s;
			showedNums.insert(s);
		}
	}
};

int main202(){
	Issue202 sol;
	int n;
	cin>>n;
	cout<<sol.isHappy(n)<<endl;
	return 0;
}